package com.blast.sspai.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.blast.sspai.R;
import com.blast.sspai.model.advertisement.Item;
import com.blast.sspai.model.articles.Data;
import com.blast.sspai.model.community.FakeItem;
import com.blast.sspai.util.CacheUtility;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by Cortana on 15/6/18.
 */
public class CommunityListAdapter extends BaseAdapter {

    /**
     * 传入的上下文
     */
    private Context mContext;
    //TODO 假模型，没有数据!!!!!!!!!!!!!!
    /**
     * 假数据
     */
    private List<FakeItem> mItemList;

    /**
     * 二级缓存工具类
     */
    private CacheUtility mCacheUtility;
    /**
     * 加载布局 Inflater
     */
    private LayoutInflater mInflater;

    /**
     * 构造函数
     *
     * @param context  ListView中传入的上下文
     * @param itemList 传入的数据
     */
    public CommunityListAdapter(Context context, List<FakeItem> itemList) {
        mItemList = itemList;
        mContext = context;
        mCacheUtility = new CacheUtility(context);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mItemList.size();
    }

    @Override
    public Object getItem(int position) {
        return mItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mItemList.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {

            convertView = mInflater.inflate(R.layout.item_community, null);
            viewHolder = new ViewHolder();
            viewHolder.userIconPic = (ImageView) convertView.findViewById(R.id.community_user_icon);
            viewHolder.commentPic = (ImageView) convertView.findViewById(R.id.community_comment_pic);
            viewHolder.contentText = (TextView) convertView.findViewById(R.id.community_content);
            viewHolder.dateText = (TextView) convertView.findViewById(R.id.community_publish_date);
            viewHolder.userNameText = (TextView) convertView.findViewById(R.id.community_user_name);
            viewHolder.commentCountText = (TextView) convertView.findViewById(R.id.community_comment_number);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        //TODO


        return convertView;
    }

    class ViewHolder {
        //用户头像
        ImageView userIconPic;
        //评论图标 评论数前面那个固定的
        ImageView commentPic;
        //评论内容
        TextView contentText;
        //日期
        TextView dateText;
        //用户名
        TextView userNameText;
        //评论数
        TextView commentCountText;
    }
}
